package com.evil.enterprise.controller;

import com.evil.application.api.RemoteApplicationButtonService;
import com.evil.application.api.RemoteButtonActionService;
import com.evil.application.pojo.dto.button.*;
import com.evil.common.application.dto.button.ButtonActionBatchReqDTO;
import com.evil.common.application.dto.button.ButtonActionReqDTO;
import com.evil.common.application.dto.order.data.ControlDataDTO;
import com.evil.common.core.entity.R;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotNull;
import java.util.List;

/**
 * 应用自定义按钮
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@RestController
@Slf4j
@AllArgsConstructor
@RequestMapping("/application/button")
public class ApplicationButtonController {

    private final RemoteApplicationButtonService remoteApplicationButtonService;

    private final RemoteButtonActionService remoteButtonActionService;

    /**
     * 新增应用按钮
     *
     * @param addButtonReqDTO addButtonReqDTO
     * @return R
     */
    @PostMapping("/add")
    public R<?> addButton(@RequestBody @Validated AddButtonReqDTO addButtonReqDTO) {
        remoteApplicationButtonService.addButton(addButtonReqDTO);
        return R.success();
    }

    /**
     * 编辑应用按钮
     *
     * @param modifyButtonReqDTO modifyButtonReqDTO
     * @return R
     */
    @PostMapping("/modify")
    public R<?> modifyButton(@RequestBody @Validated ModifyButtonReqDTO modifyButtonReqDTO) {
        remoteApplicationButtonService.modifyButton(modifyButtonReqDTO);
        return R.success();
    }

    /**
     * 复制应用按钮
     *
     * @param buttonId buttonId
     * @return R
     */
    @PostMapping("/copy")
    public R<?> modifyButton(@RequestParam("buttonId") @NotNull(message = "机器人id不能为空") Long buttonId) {
        remoteApplicationButtonService.copyButton(buttonId);
        return R.success();
    }

    /**
     * 删除按钮
     *
     * @param delButtonReqDTO delButtonReqDTO
     * @return R
     */
    @PostMapping("/del")
    public R<?> delButton(@RequestBody @Validated DelButtonReqDTO delButtonReqDTO) {
        remoteApplicationButtonService.delButton(delButtonReqDTO);
        return R.success();
    }

    /**
     * 自定义按钮列表[管理员]
     *
     * @param buttonListReqDTO buttonListReqDTO
     * @return R
     */
    @PostMapping("/list")
    public R<List<ButtonInfoRespDTO>> buttonList(@RequestBody @Validated ButtonListReqDTO buttonListReqDTO) {
        return R.success(remoteApplicationButtonService.buttonList(buttonListReqDTO));
    }

    /**
     * 根据按钮keys获取按钮列表
     *
     * @param buttonListForKeysReqDTO buttonListForKeysReqDTO
     * @return R
     */
    @PostMapping("/list-for-keys")
    public R<List<ButtonInfoRespDTO>> buttonListForKeys(@RequestBody @Validated ButtonListForKeysReqDTO buttonListForKeysReqDTO) {
        return R.success(remoteApplicationButtonService.buttonListForKeys(buttonListForKeysReqDTO));
    }

    /**
     * 按钮基础信息列表
     *
     * @param buttonListReqDTO buttonListReqDTO
     * @return List
     */
    @PostMapping("/bases")
    public R<List<ButtonBaseDTO>> bases(@RequestBody @Validated ButtonListReqDTO buttonListReqDTO) {
        return R.success(remoteApplicationButtonService.bases(buttonListReqDTO));
    }

    /**
     * 自定义按钮详情
     *
     * @param buttonInfoReqDTO buttonInfoReqDTO
     * @return R
     */
    @PostMapping("/info")
    public R<ButtonInfoRespDTO> buttonInfo(@RequestBody @Validated ButtonInfoReqDTO buttonInfoReqDTO) {
        return R.success(remoteApplicationButtonService.buttonInfo(buttonInfoReqDTO));
    }

    /**
     * 按钮动作
     *
     * @param buttonActionReqDTO buttonActionReqDTO
     * @return R
     */
    @PostMapping("/action")
    public R<List<ControlDataDTO>> buttonAction(@RequestBody @Validated ButtonActionReqDTO buttonActionReqDTO) {
        return R.success(remoteButtonActionService.buttonAction(buttonActionReqDTO));
    }

    /**
     * 按钮动作-批量（编辑数据按钮使用）
     *
     * @param buttonActionBatchReqDTO buttonActionBatchReqDTO
     * @return R
     */
    @PostMapping("/action-batch")
    public R<?> buttonAction(@RequestBody @Validated ButtonActionBatchReqDTO buttonActionBatchReqDTO) {
        return R.success(remoteButtonActionService.buttonAction(buttonActionBatchReqDTO));
    }
}
